package com.pengtu.web.project.sub;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import com.pengtu.Constants;
import com.pengtu.entity.project.SubentryInfo;
import com.pengtu.service.project.SubManager;
import com.pengtu.utils.web.Struts2Utils;
import com.pengtu.web.BaseActionSupport;
public class SubentryAction extends BaseActionSupport<SubentryInfo> {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private String id;
	private String projectId;
	private SubManager submanager;
	private SubentryInfo subentry;

	@Override
	public String list() throws Exception {
		// TODO Auto-generated method stub
		return SUCCESS;
	}

	@Override
	public String input() throws Exception {
		return INPUT;
	}

	@Override
	public String delete() throws Exception {
		submanager.deteleSubunit(id);
		Struts2Utils.renderJson(Constants.EXT_SUCCESS_JSON_STR);
		return NONE;
	}

	/* 图纸合同段子单位工程操作 */
	/**
	 * 
	 * getSubunit: 适用:查找子单位工程信息
	 * 
	 * @return
	 * @exception
	 * @since 1.0.0
	 */
	public String getSubentry() {
		SubentryInfo subentry = submanager.getSubentry("id", id);
		Struts2Utils.renderJsontoExtOneData(subentry);
		return NONE;
	}

	@Override
	protected void prepareModel() throws Exception {
		// TODO Auto-generated method stub
		if (StringUtils.isNotEmpty(id)) {
			subentry = submanager.getSubentry("id", id);
		} else {
			subentry = new SubentryInfo();
		}
	}

	@Override
	public SubentryInfo getModel() {
		// TODO Auto-generated method stub
		return subentry;
	}

	@Override
	public String save() throws Exception {
		// TODO Auto-generated method stub
		if(StringUtils.isEmpty(id)){
			String subprojectId = Struts2Utils.getParameter("subprojectId");
			subentry.setSubprojectId(subprojectId);
		}
		submanager.saveSubentry(subentry);
		String mes = "";
		if(StringUtils.isNotEmpty(id)){
			mes = "修改";
		}else{
			mes = "新增";
		}
		addActionMessage(mes+"工程分项!");
		Struts2Utils.renderJson(Constants.EXT_SUCCESS_JSON_STR);
		return NONE;
	}

	@Autowired
	public void setSubmanager(SubManager submanager) {
		this.submanager = submanager;
	}

	public String getProjectId() {
		return projectId;
	}

	public void setProjectId(String projectId) {
		this.projectId = projectId;
	}

	public void setId(String id) {
		this.id = id;
	}

	public void setSubentry(SubentryInfo subentry) {
		this.subentry = subentry;
	}

}
